<template>
    <div class="container">
        <addMedicalProduct ref="addMedicalProduct" />
        <importFileView ref="importFileView" />
        <MedicalProductApplySelf ref="MedicalProductApplySelf" />
        <div class="main">
            <div class="header felx">
                <div class="header_l flex">
                </div>
                <div class="header_r flex">
                    <div class="header_btn flex" @click="applyAccets">
                        <img src="../../assets/MedicalProductAssets_icon3.png" style="width: 13px;height: 13px;">
                        <p>物资申领</p>
                    </div>
                    <div class="serachBox flex">
                        <div class="flex">
                            <p style="width: 60px;">物资名称</p>
                        </div>
                        <input type="text" v-model="searchValue" @keyup.enter="searchEnter">
                        <button style="padding: 0 10px;" @click="getList">搜索</button>
                    </div>
                </div>
            </div>
            <div class="borderBox">
                <div class="borderTop">
                    <div class="assetsNum">物品数量：{{ total > 2000 ? "2000+" : total }}</div>
                    <div class="flex">
                    </div>
                </div>
                <div class="table_box">
                    <el-table :data="list" border style="width: 100%;" scrollTo :row-class-name="tableRowClassName"
                        :header-cell-style="headerCellStyle" :row-style="tableRowStyle">
                        <el-table-column type="index" label="序号" width="100">
                            <template #header>
                                <div class="header_icon">
                                    <span>序号</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="requestor" label="申领人">
                            <template #header>
                                <div class="header_icon">
                                    <span>申领人</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="materialName" label="申领物资">
                            <template #header>
                                <div class="header_icon">
                                    <span>申领物资</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="batchNo" label="批次号">
                            <template #header>
                                <div class="header_icon">
                                    <span>批次号</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="quantity" label="申领数量">
                            <template #header>
                                <div class="header_icon">
                                    <span>申领数量</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="price" label="单价">
                            <template #header>
                                <div class="header_icon">
                                    <span>单价</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="createdAt" label="申领日期" width="200">
                            <template #header>
                                <div class="header_icon">
                                    <span>申领日期</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="status" label="领用状态">
                            <template #header>
                                <div class="header_icon">
                                    <span>领用状态</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                            <template #default="scope">
                                {{ scope.row.status ==null?'未出库':scope.row.status ==0?'未出库':'已出库' }}
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" width="140px">
                            <template style="display: block" #default="scope">
                                <section v-if="scope.row.status ==0">
                                <el-button class="del_btn" size="small" type="danger" @click="deleteInfo(scope.row.id)">撤销
                                </el-button>
                                </section>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>

                <el-config-provider :locale="locale">
                    <div style="margin-top: 10px" class="pageBox flex">
                        <el-pagination :total="total" :current-page="page" :page-size="pageSize" background
                            layout="prev, pager, next, sizes" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                            @size-change="changePageSize" @current-change="changeCurrentPage" />
                        <div class="flex">
                            <p>第 {{ page }} 条</p>
                            <p>共 {{ total }} 条数据</p>
                        </div>
                    </div>
                </el-config-provider>
            </div>
        </div>
    </div>
</template>
<script>
import { httpService } from "@/utils/httpService";
import { formatTime1 } from "@/utils/dateFormat";
import { ElConfigProvider, ElMessage, ElMessageBox, ElLoading } from "element-plus";
import { MoreFilled, CaretLeft, CaretRight, ArrowLeftBold, ArrowRightBold, ArrowDown, Plus } from "@element-plus/icons-vue";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import addMedicalProduct from "../../components/medicalProduct/addMedicalProduct.vue"
import importFileView from "../../components/medicalProduct/importFileView.vue"
import MedicalProductApplySelf from "../../components/medicalProduct/MedicalProductApplySelf.vue"

export default {
    name: "MedicalProductLogin",
    components: {
        ElMessage, MoreFilled, ElLoading, ElMessageBox, importFileView, addMedicalProduct, Plus,
        CaretLeft, CaretRight, ArrowLeftBold, ArrowRightBold, ArrowDown, ElConfigProvider, MedicalProductApplySelf,
    },
    data() {
        return {
            page: 1,
            pageSize: 10,
            total: 0,
            list: [],
            fullscreenLoading: false,
            searchTitle: "搜索条件",
            searchValue: "",
            user: {},
            flag: false,
        };
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    computed: {},
    mounted() {
        this.user = JSON.parse(sessionStorage.getItem("user"))

        this.getList()
    },
    methods: {
        searchEnter: function (e) {
            console.log(e);
            // 使用 which 和 keyCode 属性来解决兼容问题
            var keyCode = window.event ? e.keyCode : e.which;
            var val = e.target.value;
            if (keyCode == 13 && val) {
                this.getList();
            }
        },

        tableRowClassName({ row, rowIndex }) {
            return rowIndex % 2 === 1 ? 'warning-row' : '';
        },
        headerCellStyle() {
            return {
                background: '#f2f2f2',
            };
        },
        tableRowStyle({ row, rowIndex }) {
            if (rowIndex % 2 === 1) {
                return {
                    background: '#F5F5F5',
                };
            }
        },
        reload() {
            this.getList()
        },
        changePageSize(size) {
            this.pageSize = size;
            this.getList();
        },
        changeCurrentPage(page) {
            this.page = page;
            this.getList();
        },
        addHandle() {
            this.$refs.addMedicalProduct.flag = true
            this.$refs.addMedicalProduct.title = "物资登记"
            this.$refs.addMedicalProduct.getCategoryList()
        },
        applyAccets() {
            this.$refs.MedicalProductApplySelf.flag = true
            this.$refs.MedicalProductApplySelf.applyFlag = true
            this.$refs.MedicalProductApplySelf.form.requestor = this.user.name
            this.$refs.MedicalProductApplySelf.form.requestorId = this.user.id
            this.$refs.MedicalProductApplySelf.getDepartmentList()
            this.$refs.MedicalProductApplySelf.getAssetsList()
            this.$refs.MedicalProductApplySelf.getIdList()
        },


        getList() {
            httpService(`/javaApi/stockOut/list/${this.page}/${this.pageSize}`, {
                requestor: this.user.name, materialName: this.searchValue
            }, "get").then((data) => {
                if (data) {
                    data.list.map(item => item.createdAt = formatTime1(new Date(item.createdAt)))
                    this.list = data.list
                    this.total = data.total
                }
            });
        },
        editInfo(){
            //修改后将数量同步更新到入库单和库存

        },
        deleteInfo(){
            //删除后需要将数量恢复到入库单中，更新入库单失败的话，则提示删除失败，重试！
        },

    },
};
</script>
<style scoped>
* {
    padding: 0;
    margin: 0;
}

.flex {
    display: flex;
    align-items: center;
}

.container {
    width: calc(100vw - 30px);
    height: calc(100vh - 30px);
    padding: 15px 15px;
    background-color: #EEF7FB;
}

.main {
    width: calc(100% - 30px);
    height: calc(100% - 30px);
    background-color: #fff;
    border-radius: 10px;
    padding: 15px;
}

.header {
    height: 45px;
    /* background-color: chocolate; */
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header_btn {
    width: 99px;
    height: 32px;
    background-color: #6F72FF;
    border-radius: 5px;
    justify-content: center;
    font-size: 14px;
    color: #fff;
    margin-right: 15px;
    cursor: pointer;
}

.header_btn img {
    width: 17px;
    height: 18px;
    margin-right: 5px;
}

.serachBox {
    color: #666666;
    font-size: 14px;
    width: 340px;
    height: 36px;
    border: 1px solid #D0D0D0;
    box-sizing: border-box;
    border-radius: 20px;
}

.serachBox .flex {
    justify-content: center;
    border-right: 1px solid #D0D0D0;
    margin-right: 10px;
    padding: 0 5px 0 15px;
    color: #666666;
    cursor: pointer;
}

.serachBox input {
    height: calc(100% - 4px);
    border: none;
    flex: 1;
    outline: none;
}

.serachBox button {
    width: 80px !important;
    height: 30px;
    border-radius: 15px;
    border: none;
    background-color: #6F72FF;
    color: #fff;
    font-size: 14px;
    margin-right: 2px;
    outline: none;
}


.borderBox {
    height: calc(100% - 60px);
    border: 1px solid #DFDFDF;
    border-radius: 5px;
    box-sizing: border-box;
    margin-top: 15px;
}

.borderTop {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.assetsNum {
    margin-left: 20px;
    color: #666666;
    font-size: 14px;
}

.borderTop .flex {
    margin-right: 20px;
}

.borderTop_btn {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #666666;
    margin-left: 40px;
    cursor: pointer;
}

.header_icon {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.table_box {
    width: calc(100vw - 283px);
    height: calc(100% - 93px);
    /* background-color: slategrey; */
    overflow-y: auto;
}

.el-table {
    /* margin-left: -1px; */
}

.rotate {
    transform: rotate(90deg);
}


.el-scrollbar__bar {
    z-index: 11;
    overflow-x: hidden;
    position: sticky;
}

.el-table.el-table--border {
    overflow: unset;
}


.pageBox {
    background-color: #f6f6f6;
    padding: 5px 0;
    border-top: 1px solid #e7e7e7;
    border-radius: 0 0 5px 5px;
}

.el-pagination {
    margin-left: 10px;
}

.pageBox {
    justify-content: space-between;
}

.pageBox .flex {
    color: #666;
    font-size: 14px;
    margin-right: 10px;
}

.pageBox .flex p {
    color: #666;
    font-size: 14px;
    margin-right: 20px;
}

.edit_btn {
    background-color: transparent;
    color: #007EFF;
    border: none;
}

.del_btn {
    background-color: transparent;
    color: #FF0000;
    border: none;
}

.header_l .flex p {
    margin: 0 5px;
    white-space: nowrap;
}

.el-tooltip__trigger:focus-visible {
    outline: unset;
}
</style>